package com.gitee.wsl.mathematics.geometry.d2.circle

import com.gitee.wsl.io.dataproxy.SingeProxy
import com.gitee.wsl.mathematics.geometry.d2.AbstractCloseShape
import com.gitee.wsl.mathematics.geometry.d2.base.Size
import com.gitee.wsl.mathematics.geometry.d2.contour.ShapeContour
import com.gitee.wsl.mathematics.geometry.d2.contour.contour
import com.gitee.wsl.mathematics.vector.vec2.Vec2f

class Ellipse(a: Vec2f, override var radius : Size): AbstractCloseShape(proxy = SingeProxy(a)),
    EllipseShape2d<Float, Vec2f, Size> {
    constructor(x: Number, y: Number, radiusX: Number,radiusY: Number,):this(Vec2f(x, y),Size(radiusX,radiusY))

    //override fun getBounds() = Rectangle(center.x - radius.width, center.y - radius.height, center.x + radius.width, center.y + radius.height)

    companion object{

    }

    override val contour: ShapeContour
        get() {
            val x = center.x - xRadius
            val y = center.y - yRadius
            val width = xRadius * 2.0
            val height = yRadius * 2.0
            val kappa = 0.5522848
            val ox = width / 2 * kappa        // control point offset horizontal
            val oy = height / 2 * kappa        // control point offset vertical
            val xe = x + width        // x-end
            val ye = y + height        // y-end
            val xm = x + width / 2        // x-middle
            val ym = y + height / 2       // y-middle

            return contour {
                moveTo(Vec2f(x, ym))
                curveTo(Vec2f(x, ym - oy), Vec2f(xm - ox, y), Vec2f(xm, y))
                curveTo(Vec2f(xm + ox, y), Vec2f(xe, ym - oy), Vec2f(xe, ym))
                curveTo(Vec2f(xe, ym + oy), Vec2f(xm + ox, ye), Vec2f(xm, ye))
                curveTo(Vec2f(xm - ox, ye), Vec2f(x, ym + oy), Vec2f(x, ym))
                close()
            }
        }
}